## Women Talking: Bringing the Environment into UK Parliamentary Debates 
## Data Preparation

install.packages("dplyr")
library(dplyr)
install.packages("ggplot2")
library(ggplot2)
install.packages("tidyverse")
library(tidyverse)
install.packages("stargazer")
library(stargazer)
install.packages("jtools")
library(jtools)
install.packages("ExPanDaR")
library(ExPanDaR)
install.packages("sandwich")
library(sandwich)
install.packages("lmtest")
library(lmtest)
install.packages("tseries")
library(tseries)
install.packages("foreign")
library(foreign)
install.packages("stringr")
library(stringr)
install.packages("quanteda")
library(quanteda)
library(ggplot2)

Speeches<-read.csv(".../hansard-speeches-v310.csv")
Speeches<-subset(Speeches, date>="2010-11-05") ## first day of David Cameron Prime Ministership (beg. of conserv. govt)
keep<-c("mnis_id", "speakername", "date", "year", "party", "speech", "constituency", "speech_class", "major_heading", "minor_heading")
Speeches<-Speeches[,keep] ## 707,022 observations
nrow(Speeches)
View(Speeches)
max(Speeches$date)## 2021-04-29

### DO NOT NEED TO RUN: This is how I determined which speakers were not appearing in the House of Commons gender/govt&opp role data
Gender<-read.csv("/Users/hannahsalamon/Desktop/Ongoing Research/Speeches/HansardSpeechData/GenderData.csv")
SpeechesGender<- merge(Speeches, Gender, by = "mnis_id", all.x = TRUE)
gender_counts <- table(SpeechesGender$gender, useNA = "ifany")
print(gender_counts)
Speeches2NA <- SpeechesGender[is.na(SpeechesGender$gender), ]
View(Speeches2NA)
unique(Speeches2NA$speakername.x)
Names<-table(unique(Speeches2NA$speakername), Speeches2NA$mnis_id)
## Export this dataset of gender=NA to manually populate it
keep<-c("mnis_id", "speakername", "start_date", "gender", "gvt_role", "opp_role", "parly_role")
Speeches2NA<-Speeches2NA[,keep] ## 707,022 observations
Speeches2NA <- distinct(Speeches2NA)
write.csv(Speeches2NA, "ManualGenderData.csv", row.names = FALSE, quote = TRUE) ## this is a table of all the people from the Hansard speech data
### On this basis I manually constructed the gender, etc. information, added it to existing gender data, and that is what is read in below.

## Read in Total Gender Data
Gender<-read.csv("/Users/hannahsalamon/Desktop/Ongoing Research/Speeches/2010 Analysis/TotalGenderData.csv") ### TotalGender is both indexed + manual gender data
View(Gender)
nrow(Gender)

#Merging speech to gender data
Speeches <- merge(Speeches, Gender, by = "mnis_id", all.x = TRUE)
nrow(Speeches) ## 709,088
Speeches<-subset(Speeches, speech_class=="Speech") ## remove procedural speeches
nrow(Speeches) ## 687,669 Speeches Total
max(Speeches$date) ## 2021-04-29: maintains all data across time
View(Speeches)
Speeches<-rename(Speeches, speakername=speakername.x)
Speeches$speakername.y <- NULL
View(Speeches)
Speeches <- Speeches %>% mutate(gvt_role = ifelse(is.na(gvt_role), 0, gvt_role))
Speeches <- Speeches %>% mutate(opp_role = ifelse(is.na(opp_role), 0, opp_role))
Speeches <- Speeches %>% mutate(parly_role = ifelse(is.na(parly_role), 0, parly_role))

##Create YearsExp
Speeches$YearsExp<-Speeches$year-Speeches$start_date


## Add in committee data-- Energy and Climate Change Committee, Energy Security and Net Zero Committee, Environment, Food, and Rural Affairs Committee, 
## Environmental Audit Committee, Environmental Audit Sub-Committee on Polar Research
One<-read.csv("/Users/hannahsalamon/Desktop/Ongoing Research/Speeches/2010 Analysis/Committee Raw Data/Committee1.csv")
Two<-read.csv("/Users/hannahsalamon/Desktop/Ongoing Research/Speeches/2010 Analysis/Committee Raw Data/Committee2.csv")
Three<-read.csv("/Users/hannahsalamon/Desktop/Ongoing Research/Speeches/2010 Analysis/Committee Raw Data/Committee3.csv")
Four<-read.csv("/Users/hannahsalamon/Desktop/Ongoing Research/Speeches/2010 Analysis/Committee Raw Data/Committee4.csv")
Five<-read.csv("/Users/hannahsalamon/Desktop/Ongoing Research/Speeches/2010 Analysis/Committee Raw Data/Committee5.csv")

Committee <- merge(One, Two, by = "Name", all = TRUE)
Committee<-merge(Committee, Three, by = "Name", all = TRUE)
Committee<-merge(Committee, Four, by = "Name", all = TRUE)
Committee<-merge(Committee, Five, by = "Name", all = TRUE)
Committee <- Committee %>% mutate(EnergyClimChange = ifelse(is.na(EnergyClimChange), 0, EnergyClimChange), 
                                  EnSecNetZero = ifelse(is.na(EnSecNetZero), 0, EnSecNetZero), 
                                  EnvFoodRurAffairs = ifelse(is.na(EnvFoodRurAffairs), 0, EnvFoodRurAffairs), 
                                  EnvAudCommittee = ifelse(is.na(EnvAudCommittee), 0, EnvAudCommittee), 
                                  PolarResearc = ifelse(is.na(PolarResearc), 0, PolarResearc))
Committee$EnvCommittee<-rowSums(cbind(Committee$EnergyClimChange, Committee$EnSecNetZero,Committee$EnvFoodRurAffairs,
                                      Committee$EnvAudCommittee, Committee$PolarResearc))
Committee$EnergyClimChange <- NULL
Committee$EnSecNetZero <- NULL
Committee$EnvFoodRurAffairs <- NULL
Committee$EnvAudCommittee <- NULL
Committee$PolarResearc <- NULL
Committee$EnvCommittee <- ifelse(Committee$EnvCommittee >= 1, 1, 0)
Committee<-rename(Committee, speakername=Name)
Speeches <- merge(Speeches, Committee, by = "speakername", all.x = TRUE)
Speeches <- Speeches %>% mutate(EnvCommittee = ifelse(is.na(EnvCommittee), 0, EnvCommittee))
max(Speeches$date)## 2021-04-29
## Create ruling party dummy 
Speeches$RulingParty[grepl("\\<Conservative\\>", Speeches$party, ignore.case = TRUE)] <- 1
Speeches <- Speeches %>% mutate(RulingParty = ifelse(is.na(RulingParty), 0, RulingParty))
View(Speeches)
nrow(Speeches)## 687,669
max(Speeches$date)## 2021-04-29

##Creaing EnvWords: searching through speeches for unambiguous environmental words/phrases
Speeches$Agenda2030[grepl("\\<Agenda 2030\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$AirQuality[grepl("\\<air quality\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$AltEnergy[grepl("\\<alternative energ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$AltFuel[grepl("\\<alternative fuel.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$AnimalKingdom[grepl("\\<animal kingdom.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Biodegradable[grepl("\\<biodegradabl.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Biodiverse[grepl("\\<biodivers.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$C02[grepl("\\<C02\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonBudget[grepl("\\<carbon budget.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonCapture[grepl("\\<carbon captur.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonDioxide[grepl("\\<carbon dioxide\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonEmissions[grepl("\\<carbon emission.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonFootprint[grepl("\\<carbon footprint.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonNeutral[grepl("\\<carbon neutral\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonPrice[grepl("\\<carbon pric.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonStorage[grepl("\\<carbon storage\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonTarget[grepl("\\<carbon target.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CarbonTax[grepl("\\<carbon tax.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CircularEconomy[grepl("\\<circular econom.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CleanEnergy[grepl("\\<clean energ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CleanGrowth[grepl("\\<clean growth\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateAction[grepl("\\<climate action.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateActivistm[grepl("\\<climate activis.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateChange[grepl("\\<climate change\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateCrisis[grepl("\\<climate cris.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateDiplomacy[grepl("\\<climate diploma.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateEmergency[grepl("\\<climate emergency\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateFriendly1[grepl("\\<climate friendly\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateFriendly2[grepl("\\<climate-friendly\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateFund[grepl("\\<climate fund.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateGoals[grepl("\\<climate goal.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateIssues[grepl("\\<climate issue.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateResilient1[grepl("\\<climate resilien.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateResilient2[grepl("\\<climate-resilien.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ClimateSummit[grepl("\\<climate summit.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ConservationWork[grepl("\\<conservation work.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$COP26[grepl("\\<COP26\\>",Speeches$speech)] <- 1
Speeches$COP27[grepl("\\<COP27\\>",Speeches$speech)] <- 1
Speeches$COP28[grepl("\\<COP28\\>",Speeches$speech)] <- 1
Speeches$CoralReefs[grepl("\\<coral reef.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$CutEmissions[grepl("\\<cut.* emission.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Decarbon[grepl("\\<decarbon.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Deforestation[grepl("\\<deforestation\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$DEFRA1[grepl("\\<DEFRA\\>",Speeches$speech)] <- 1
Speeches$DEFRA2[grepl("\\<Department for Environment, food, and rural affairs\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EcolEmergency[grepl("\\<ecologial emergency\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Ecology[grepl("\\<ecolog.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ElectricCars[grepl("\\<electric car.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ElectricVehicles[grepl("\\<electric vehicl.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EmissionsTrading[grepl("\\<emissions trad.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EndangeredAnimals[grepl("\\<endangered animal.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EndangeredSpecies[grepl("\\<endangered species\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnCleanGrowth[grepl("\\<energy and clean growth\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnergyEfficiency[grepl("\\<energy efficien.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnergyPolicy[grepl("\\<energy polic.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnergyTransition[grepl("\\<energy transition\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentAgency[grepl("\\<environment.* agency\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentActivism[grepl("\\<environmental activi.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalAudit[grepl("\\<environmental audit.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalConcern[grepl("\\<environmental concern.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalDamage[grepl("\\<environmental damage.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalDestruction[grepl("\\<environmental destruction\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalImprPlan[grepl("\\<environmental improvement plan.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalIssue[grepl("\\<environmental issue.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalLeg[grepl("\\<environmental legislation\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalPlan[grepl("\\<environmental plan.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalProtection[grepl("\\<environmental protect.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalRegulation[grepl("\\<environmental regulat.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalStandards[grepl("\\<environmental standard.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalSus[grepl("\\<environment.* sustaina.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ETS[grepl("\\<ETS\\>",Speeches$speech)] <- 1
Speeches$FeedInTariff1[grepl("\\<feed-in tariff.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$FeedInTariff2[grepl("\\<feed in tariff.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ForestPreservation[grepl("\\<forest preservation\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$FossilFuel[grepl("\\<fossil fuel.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Geothermal[grepl("\\<geothermal\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GlobalWarming[grepl("\\<global warming\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenBelt[grepl("\\<green belt.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenEconomy[grepl("\\<green econom.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenEnergy[grepl("\\<green energ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenFinance[grepl("\\<green financ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenFuture[grepl("\\<green futur.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenHomes[grepl("\\<green home.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenHousing[grepl("\\<green hous.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenIndRev[grepl("\\<green industrial revolution\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenIndustry[grepl("\\<green industr.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenInvestment[grepl("\\<green invest.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenJobs[grepl("\\<green job.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenNewDeal[grepl("\\<green new deal.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenProducts[grepl("\\<green product.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenRecovery[grepl("\\<green recovery\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenRevolution[grepl("\\<green revolution\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenTech[grepl("\\<green tech.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenTransition[grepl("\\<green transition.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenerFuture[grepl("\\<green.* future\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$GreenhouseGas[grepl("\\<greenhouse gas.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$HabitatHotsp[grepl("\\<habitat hotspot.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$HighCarbon1[grepl("\\<high carbon.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$HighCarbon2[grepl("\\<high-carbon.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$HydroPower[grepl("\\<hydro power\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$IEA[grepl("\\<IEA\\>",Speeches$speech)] <- 1
Speeches$InterPCC[grepl("\\<Intergovernmental Panel on Climate Change\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$InterEA[grepl("\\<International Energy Agency\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$IPCC[grepl("\\<IPCC\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$JustTransition[grepl("\\<Just Transition\\>",Speeches$speech)] <- 1
Speeches$LandConservation[grepl("\\<land conservation\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$LowCarbon1[grepl("\\<low carbon\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$LowCarbon2[grepl("\\<low-carbon\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$MarineCons[grepl("\\<marine conservation\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$MarineEnvironment[grepl("\\<marine environment\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Methane[grepl("\\<methane\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Microplastic[grepl("\\<microplastic.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$NativeSpecies[grepl("\\<native species\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$NaturalWorld[grepl("\\<natural world\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$NetZero[grepl("\\<net zero\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$OceanConservation[grepl("\\<ocean conservation\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$OffshoreWind1[grepl("\\<offshore wind\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$OffshoreWind2[grepl("\\<off-shore wind\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Ozone[grepl("\\<ozone\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ParisAccord[grepl("\\<Paris Accord\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ParisAgreement[grepl("\\<Paris Agreement\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ParisClimate[grepl("\\<Paris Climate\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$PlasticWaste[grepl("\\<plastic waste\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Pollution[grepl("\\<pollution\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ProtectEnv[grepl("\\<protect.* the environment\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ProtectedHabitats[grepl("\\<protected habitats\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$Recycle[grepl("\\<recylc.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$RenewableEnergy[grepl("\\<renewable energy\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$RenewablePower[grepl("\\<renewable power\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SeaLevel[grepl("\\<sea level\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SingleUse[grepl("\\<single use\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SingleUse2[grepl("\\<single-use\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SmartEnergy[grepl("\\<smart energ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SolarEnergy[grepl("\\<solar energ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SolarPanel[grepl("\\<solar panel.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SolarPV[grepl("\\<solar PV.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SolarThermal[grepl("\\<solar thermal\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SustainableEnergy[grepl("\\<sustainable energ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SustainableForestry[grepl("\\<sustainable forestry\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SustainableFuture[grepl("\\<sustainable future\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$SustainableInfra[grepl("\\<sustainable infrastructure\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$WildlifeCons[grepl("\\<wildlife conserv.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$WildlifePres[grepl("\\<wildlife preserv.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$WildlifeSanct[grepl("\\<wildlife sanctuar.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$WindEnergy[grepl("\\<wind energ.*\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$WindPower[grepl("\\<wind power\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ZeroCarbon1[grepl("\\<zero carbon\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ZeroCarbon2[grepl("\\<zero-carbon\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ZeroEmissions1[grepl("\\<zero emissions\\>",Speeches$speech, ignore.case = TRUE)] <- 1
Speeches$ZeroEmissions2[grepl("\\<zero-emissions\\>",Speeches$speech, ignore.case = TRUE)] <- 1


## Make all NAs into 0s
Speeches <- Speeches %>% mutate(Agenda2030 = ifelse(is.na(Agenda2030), 0, Agenda2030),
                                AirQuality = ifelse(is.na(AirQuality), 0, AirQuality), 
                                AltEnergy = ifelse(is.na(AltEnergy), 0, AltEnergy),
                                AltFuel = ifelse(is.na(AltFuel), 0, AltFuel),
                                AnimalKingdom= ifelse(is.na(AnimalKingdom), 0, AnimalKingdom),
                                Biodegradable = ifelse(is.na(Biodegradable), 0, Biodegradable),
                                Biodiverse = ifelse(is.na(Biodiverse), 0, Biodiverse),
                                C02 = ifelse(is.na(C02), 0, C02),
                                CarbonBudget = ifelse(is.na(CarbonBudget), 0, CarbonBudget),
                                CarbonCapture = ifelse(is.na(CarbonCapture), 0, CarbonCapture),
                                CarbonDioxide = ifelse(is.na(CarbonDioxide), 0, CarbonDioxide),
                                CarbonEmissions = ifelse(is.na(CarbonEmissions), 0, CarbonEmissions),
                                CarbonFootprint = ifelse(is.na(CarbonFootprint), 0, CarbonFootprint),
                                CarbonNeutral = ifelse(is.na(CarbonNeutral), 0, CarbonNeutral),
                                CarbonPrice = ifelse(is.na(CarbonPrice), 0, CarbonPrice),
                                CarbonStorage = ifelse(is.na(CarbonStorage), 0, CarbonStorage),
                                CarbonTarget = ifelse(is.na(CarbonTarget), 0, CarbonTarget),
                                CarbonTax = ifelse(is.na(CarbonTax), 0, CarbonTax),
                                CircularEconomy = ifelse(is.na(CircularEconomy), 0, CircularEconomy),
                                CleanEnergy = ifelse(is.na(CleanEnergy), 0, CleanEnergy),
                                CleanGrowth = ifelse(is.na(CleanGrowth), 0, CleanGrowth),
                                ClimateAction = ifelse(is.na(ClimateAction), 0, ClimateAction),
                                ClimateActivistm = ifelse(is.na(ClimateActivistm), 0, ClimateActivistm),
                                ClimateChange = ifelse(is.na(ClimateChange), 0, ClimateChange),
                                ClimateCrisis = ifelse(is.na(ClimateCrisis), 0, ClimateCrisis),
                                ClimateDiplomacy = ifelse(is.na(ClimateDiplomacy), 0, ClimateDiplomacy),
                                ClimateEmergency = ifelse(is.na(ClimateEmergency), 0, ClimateEmergency),
                                ClimateFriendly1 = ifelse(is.na(ClimateFriendly1), 0, ClimateFriendly1),
                                ClimateFriendly2 = ifelse(is.na(ClimateFriendly2), 0, ClimateFriendly2),
                                ClimateFund = ifelse(is.na(ClimateFund), 0, ClimateFund),
                                ClimateGoals = ifelse(is.na(ClimateGoals), 0, ClimateGoals),
                                ClimateIssues = ifelse(is.na(ClimateIssues), 0, ClimateIssues),
                                ClimateResilient1 = ifelse(is.na(ClimateResilient1), 0, ClimateResilient1),
                                ClimateResilient2 = ifelse(is.na(ClimateResilient2), 0, ClimateResilient2),
                                ClimateSummit = ifelse(is.na(ClimateSummit), 0, ClimateSummit),
                                ConservationWork = ifelse(is.na(ConservationWork), 0, ConservationWork),
                                COP26 = ifelse(is.na(COP26), 0, COP26),
                                COP27= ifelse(is.na(COP27), 0, COP27),
                                COP28 = ifelse(is.na(COP28), 0, COP28),
                                CoralReefs = ifelse(is.na(CoralReefs), 0, CoralReefs),
                                CutEmissions = ifelse(is.na(CutEmissions), 0, CutEmissions),
                                Decarbon = ifelse(is.na(Decarbon), 0, Decarbon),
                                Deforestation = ifelse(is.na(Deforestation), 0, Deforestation),
                                DEFRA1 = ifelse(is.na(DEFRA1), 0, DEFRA1),
                                DEFRA2 = ifelse(is.na(DEFRA2), 0, DEFRA2),
                                EcolEmergency = ifelse(is.na(EcolEmergency), 0, EcolEmergency),
                                Ecology = ifelse(is.na(Ecology), 0, Ecology),
                                ElectricCars = ifelse(is.na(ElectricCars), 0, ElectricCars),
                                ElectricVehicles = ifelse(is.na(ElectricVehicles), 0, ElectricVehicles),
                                EmissionsTrading = ifelse(is.na(EmissionsTrading), 0, EmissionsTrading),
                                EndangeredAnimals = ifelse(is.na(EndangeredAnimals), 0, EndangeredAnimals),
                                EndangeredSpecies = ifelse(is.na(EndangeredSpecies), 0, EndangeredSpecies),
                                EnCleanGrowth = ifelse(is.na(EnCleanGrowth), 0, EnCleanGrowth),
                                EnergyEfficiency = ifelse(is.na(EnergyEfficiency), 0, EnergyEfficiency),
                                EnergyPolicy = ifelse(is.na(EnergyPolicy), 0, EnergyPolicy),
                                EnergyTransition = ifelse(is.na(EnergyTransition), 0, EnergyTransition),
                                EnvironmentAgency = ifelse(is.na(EnvironmentAgency), 0, EnvironmentAgency),
                                EnvironmentActivism= ifelse(is.na(EnvironmentActivism), 0, EnvironmentActivism),
                                EnvironmentalAudit = ifelse(is.na(EnvironmentalAudit), 0, EnvironmentalAudit),
                                EnvironmentalConcern = ifelse(is.na(EnvironmentalConcern), 0, EnvironmentalConcern),
                                EnvironmentalDamage = ifelse(is.na(EnvironmentalDamage), 0, EnvironmentalDamage),
                                EnvironmentalDestruction = ifelse(is.na(EnvironmentalDestruction), 0, EnvironmentalDestruction),
                                EnvironmentalImprPlan = ifelse(is.na(EnvironmentalImprPlan), 0, EnvironmentalImprPlan),
                                EnvironmentalIssue = ifelse(is.na(EnvironmentalIssue), 0, EnvironmentalIssue),
                                EnvironmentalLeg = ifelse(is.na(EnvironmentalLeg), 0, EnvironmentalLeg),
                                EnvironmentalPlan = ifelse(is.na(EnvironmentalPlan), 0, EnvironmentalPlan),
                                EnvironmentalProtection = ifelse(is.na(EnvironmentalProtection), 0, EnvironmentalProtection),
                                EnvironmentalRegulation = ifelse(is.na(EnvironmentalRegulation), 0, EnvironmentalRegulation),
                                EnvironmentalStandards = ifelse(is.na(EnvironmentalStandards), 0, EnvironmentalStandards),
                                EnvironmentalSus= ifelse(is.na(EnvironmentalSus), 0, EnvironmentalSus),
                                ETS = ifelse(is.na(ETS), 0, ETS),
                                FeedInTariff1 = ifelse(is.na(FeedInTariff1), 0, FeedInTariff1),
                                FeedInTariff2 = ifelse(is.na(FeedInTariff2), 0, FeedInTariff2),
                                ForestPreservation= ifelse(is.na(ForestPreservation), 0, ForestPreservation),
                                FossilFuel = ifelse(is.na(FossilFuel), 0, FossilFuel),
                                Geothermal = ifelse(is.na(Geothermal), 0, Geothermal),
                                GlobalWarming = ifelse(is.na(GlobalWarming), 0, GlobalWarming),
                                GreenBelt = ifelse(is.na(GreenBelt), 0, GreenBelt),
                                GreenEconomy= ifelse(is.na(GreenEconomy), 0, GreenEconomy),
                                GreenEnergy = ifelse(is.na(GreenEnergy), 0, GreenEnergy),
                                GreenFinance = ifelse(is.na(GreenFinance), 0, GreenFinance),
                                GreenFuture = ifelse(is.na(GreenFuture), 0, GreenFuture),
                                GreenHomes = ifelse(is.na(GreenHomes), 0, GreenHomes),
                                GreenHousing = ifelse(is.na(GreenHousing), 0, GreenHousing),
                                GreenIndRev = ifelse(is.na(GreenIndRev), 0, GreenIndRev),
                                GreenIndustry = ifelse(is.na(GreenIndustry), 0, GreenIndustry),
                                GreenInvestment = ifelse(is.na(GreenInvestment), 0, GreenInvestment),
                                GreenJobs = ifelse(is.na(GreenJobs), 0, GreenJobs),
                                GreenNewDeal = ifelse(is.na(GreenNewDeal), 0, GreenNewDeal),
                                GreenProducts = ifelse(is.na(GreenProducts), 0, GreenProducts),
                                GreenRecovery = ifelse(is.na(GreenRecovery), 0, GreenRecovery),
                                GreenRevolution = ifelse(is.na(GreenRevolution), 0, GreenRevolution),
                                GreenTech = ifelse(is.na(GreenTech), 0, GreenTech),
                                GreenTransition = ifelse(is.na(GreenTransition), 0, GreenTransition),
                                GreenerFuture = ifelse(is.na(GreenerFuture), 0, GreenerFuture),
                                GreenhouseGas= ifelse(is.na(GreenhouseGas), 0, GreenhouseGas),
                                HabitatHotsp= ifelse(is.na(HabitatHotsp), 0, HabitatHotsp),
                                HighCarbon1= ifelse(is.na(HighCarbon1), 0, HighCarbon1),
                                HighCarbon2= ifelse(is.na(HighCarbon2), 0, HighCarbon2),
                                HydroPower= ifelse(is.na(HydroPower), 0, HydroPower),
                                IEA= ifelse(is.na(IEA), 0, IEA),
                                InterPCC = ifelse(is.na(InterPCC), 0, InterPCC),
                                InterEA = ifelse(is.na(InterEA), 0, InterEA),
                                IPCC = ifelse(is.na(IPCC), 0, IPCC),
                                JustTransition = ifelse(is.na(JustTransition), 0, JustTransition),
                                LandConservation = ifelse(is.na(LandConservation), 0, LandConservation),
                                LowCarbon1 = ifelse(is.na(LowCarbon1), 0, LowCarbon1),
                                LowCarbon2 = ifelse(is.na(LowCarbon2), 0, LowCarbon2),
                                MarineCons = ifelse(is.na(MarineCons), 0, MarineCons),
                                MarineEnvironment = ifelse(is.na(MarineEnvironment), 0, MarineEnvironment),
                                Methane = ifelse(is.na(Methane), 0, Methane),
                                Microplastic = ifelse(is.na(Microplastic), 0, Microplastic),
                                NativeSpecies= ifelse(is.na(NativeSpecies), 0, NativeSpecies),
                                NaturalWorld = ifelse(is.na(NaturalWorld), 0, NaturalWorld),
                                NetZero = ifelse(is.na(NetZero), 0, NetZero),
                                OceanConservation = ifelse(is.na(OceanConservation), 0, OceanConservation),
                                OffshoreWind1= ifelse(is.na(OffshoreWind1), 0, OffshoreWind1),
                                OffshoreWind2= ifelse(is.na(OffshoreWind2), 0, OffshoreWind2),
                                Ozone = ifelse(is.na(Ozone), 0, Ozone),
                                ParisAccord = ifelse(is.na(ParisAccord), 0, ParisAccord),
                                ParisAgreement = ifelse(is.na(ParisAgreement), 0, ParisAgreement),
                                ParisClimate = ifelse(is.na(ParisClimate), 0, ParisClimate),
                                PlasticWaste = ifelse(is.na(PlasticWaste), 0, PlasticWaste),
                                Pollution = ifelse(is.na(Pollution), 0, Pollution),
                                ProtectEnv = ifelse(is.na(ProtectEnv), 0, ProtectEnv), 
                                ProtectedHabitats = ifelse(is.na(ProtectedHabitats), 0, ProtectedHabitats), 
                                Recycle = ifelse(is.na(Recycle), 0, Recycle),
                                RenewableEnergy = ifelse(is.na(RenewableEnergy), 0, RenewableEnergy),
                                RenewablePower = ifelse(is.na(RenewablePower), 0, RenewablePower),
                                SeaLevel = ifelse(is.na(SeaLevel), 0, SeaLevel),
                                SingleUse = ifelse(is.na(SingleUse), 0, SingleUse),
                                SingleUse2 = ifelse(is.na(SingleUse2), 0, SingleUse2), 
                                SmartEnergy = ifelse(is.na(SmartEnergy), 0, SmartEnergy),
                                SolarEnergy = ifelse(is.na(SolarEnergy), 0, SolarEnergy),
                                SolarPanel = ifelse(is.na(SolarPanel), 0, SolarPanel),
                                SolarPV = ifelse(is.na(SolarPV), 0, SolarPV),
                                SolarThermal = ifelse(is.na(SolarThermal), 0, SolarThermal),
                                SustainableEnergy = ifelse(is.na(SustainableEnergy), 0, SustainableEnergy),
                                SustainableForestry = ifelse(is.na(SustainableForestry), 0, SustainableForestry),
                                SustainableFuture = ifelse(is.na(SustainableFuture), 0, SustainableFuture),
                                SustainableInfra = ifelse(is.na(SustainableInfra), 0, SustainableInfra),
                                WildlifeCons = ifelse(is.na(WildlifeCons), 0, WildlifeCons),
                                WildlifePres = ifelse(is.na(WildlifePres), 0, WildlifePres),
                                WildlifeSanct = ifelse(is.na(WildlifeSanct), 0, WildlifeSanct),
                                WindEnergy = ifelse(is.na(WindEnergy), 0, WindEnergy),
                                WindPower = ifelse(is.na(WindPower), 0, WindPower),
                                ZeroCarbon1 = ifelse(is.na(ZeroCarbon1), 0, ZeroCarbon1),
                                ZeroCarbon2 = ifelse(is.na(ZeroCarbon2), 0, ZeroCarbon2),
                                ZeroEmissions1 = ifelse(is.na(ZeroEmissions1), 0, ZeroEmissions1),
                                ZeroEmissions2 = ifelse(is.na(ZeroEmissions2), 0, ZeroEmissions2))


## add all variables to quantify the # of environmental words/phrases per speech
Speeches$EnvWords<-rowSums(cbind(Speeches$Agenda2030, Speeches$AirQuality ,Speeches$AltEnergy, Speeches$AltFuel, Speeches$AnimalKingdom, Speeches$Biodegradable, 
                                 Speeches$Biodiverse, Speeches$C02, Speeches$CarbonBudget , Speeches$CarbonCapture, Speeches$CarbonDioxide, Speeches$CarbonEmissions, 
                                 Speeches$CarbonFootprint,Speeches$CarbonNeutral, Speeches$CarbonPrice , Speeches$CarbonStorage , Speeches$CarbonTarget , 
                                 Speeches$CarbonTax ,Speeches$CircularEconomy ,Speeches$CleanEnergy , Speeches$CleanGrowth , Speeches$ClimateAction, 
                                 Speeches$ClimateActivistm , Speeches$ClimateChange ,Speeches$ClimateCrisis , Speeches$ClimateDiplomacy , Speeches$ClimateEmergency,
                                 Speeches$ClimateFriendly1,Speeches$ClimateFriendly2, Speeches$ClimateFund , Speeches$ClimateGoals , Speeches$ClimateIssues ,
                                 Speeches$ClimateResilient1, Speeches$ClimateResilient2 , Speeches$ClimateSummit ,  Speeches$ConservationWork ,  Speeches$COP26 ,
                                 Speeches$COP27, Speeches$COP28 , Speeches$CoralReefs, Speeches$CutEmissions ,Speeches$Decarbon , Speeches$Deforestation, Speeches$DEFRA1,
                                 Speeches$DEFRA2, Speeches$EcolEmergency , Speeches$Ecology ,Speeches$ElectricCars ,Speeches$ElectricVehicles , Speeches$EmissionsTrading ,
                                 Speeches$EndangeredAnimals , Speeches$EndangeredSpecies ,  Speeches$EnCleanGrowth , Speeches$EnergyEfficiency , Speeches$EnergyPolicy, 
                                 Speeches$EnergyTransition ,Speeches$EnvironmentAgency , Speeches$EnvironmentActivism,  Speeches$EnvironmentalAudit ,  
                                 Speeches$EnvironmentalConcern, Speeches$EnvironmentalDamage ,  Speeches$EnvironmentalDestruction, 
                                 Speeches$EnvironmentalImprPlan,Speeches$EnvironmentalIssue, Speeches$EnvironmentalLeg , Speeches$EnvironmentalPlan ,  
                                 Speeches$EnvironmentalProtection , Speeches$EnvironmentalRegulation ,Speeches$EnvironmentalStandards ,Speeches$EnvironmentalSus, Speeches$ETS ,
                                 Speeches$FeedInTariff1 , Speeches$FeedInTariff2 ,Speeches$ForestPreservation, Speeches$FossilFuel , Speeches$Geothermal ,Speeches$GlobalWarming ,
                                 Speeches$GreenBelt , Speeches$GreenEconomy, Speeches$GreenEnergy , Speeches$GreenFinance, Speeches$GreenFuture , Speeches$GreenHomes ,Speeches$GreenHousing , 
                                 Speeches$GreenIndRev , Speeches$GreenIndustry, Speeches$GreenInvestment ,  Speeches$GreenJobs , Speeches$GreenNewDeal , Speeches$GreenProducts ,
                                 Speeches$GreenRecovery, Speeches$GreenRevolution, Speeches$GreenTech , Speeches$GreenTransition , Speeches$GreenerFuture , 
                                 Speeches$GreenhouseGas, Speeches$HabitatHotsp, Speeches$HighCarbon1,  Speeches$HighCarbon2, Speeches$HydroPower, Speeches$IEA, Speeches$InterPCC , 
                                 Speeches$InterEA , Speeches$IPCC,  Speeches$JustTransition , Speeches$LandConservation , Speeches$LowCarbon1, Speeches$LowCarbon2 , Speeches$MarineCons ,
                                 Speeches$MarineEnvironment , Speeches$Methane ,  Speeches$Microplastic, Speeches$NativeSpecies, Speeches$NaturalWorld ,  Speeches$NetZero , 
                                 Speeches$OceanConservation,Speeches$OffshoreWind1,  Speeches$OffshoreWind2, Speeches$Ozone , Speeches$ParisAccord,  Speeches$ParisAgreement , 
                                 Speeches$ParisClimate , Speeches$PlasticWaste, Speeches$Pollution , Speeches$ProtectEnv , Speeches$ProtectedHabitats, Speeches$Recycle , 
                                 Speeches$RenewableEnergy , Speeches$RenewablePower, Speeches$SeaLevel , Speeches$SingleUse , Speeches$SingleUse2, Speeches$SmartEnergy , Speeches$SolarEnergy , 
                                 Speeches$SolarPanel ,Speeches$SolarPV ,Speeches$SolarThermal ,   Speeches$SustainableEnergy , Speeches$SustainableForestry , 
                                 Speeches$SustainableFuture , Speeches$SustainableInfra , Speeches$WildlifeCons , Speeches$WildlifePres,  Speeches$WildlifeSanct , 
                                 Speeches$WindEnergy, Speeches$WindPower ,Speeches$ZeroCarbon1 , Speeches$ZeroCarbon2, Speeches$ZeroEmissions1, Speeches$ZeroEmissions2 ))

## Immediately delete all the unnecessary unambiguous vocab variables AND speech variable 
keep<-c("mnis_id", "speakername", "date", "year", "party", "constituency", "speech_class", "major_heading", "minor_heading", "gender", "start_date", "gvt_role", "opp_role", "parly_role", "EnvCommittee", "EnvWords", "YearsExp", "RulingParty")
Speeches<-Speeches[,keep]

##Coding EnvWords--> EnvDummy as 1 if any appear
Speeches$EnvDummy <- ifelse(Speeches$EnvWords >= 1, 1, 0)

## Extracting environmental debate topics

Speeches$Agenda2030[grepl("\\<Agenda 2030\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$AirQuality[grepl("\\<air quality\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$AltEnergy[grepl("\\<alternative energ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$AltFuel[grepl("\\<alternative fuel.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$AnimalKingdom[grepl("\\<animal kingdom.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Biodegradable[grepl("\\<biodegradabl.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Biodiverse[grepl("\\<biodivers.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$C02[grepl("\\<C02\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonBudget[grepl("\\<carbon budget.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonCapture[grepl("\\<carbon captur.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonDioxide[grepl("\\<carbon dioxide\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonEmissions[grepl("\\<carbon emission.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonFootprint[grepl("\\<carbon footprint.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonNeutral[grepl("\\<carbon neutral\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonPrice[grepl("\\<carbon pric.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonStorage[grepl("\\<carbon storage\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonTarget[grepl("\\<carbon target.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CarbonTax[grepl("\\<carbon tax.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CircularEconomy[grepl("\\<circular econom.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CleanEnergy[grepl("\\<clean energ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CleanGrowth[grepl("\\<clean growth\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateAction[grepl("\\<climate action.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateActivistm[grepl("\\<climate activis.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateChange[grepl("\\<climate change\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateCrisis[grepl("\\<climate cris.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateDiplomacy[grepl("\\<climate diploma.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateEmergency[grepl("\\<climate emergency\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateFriendly1[grepl("\\<climate friendly\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateFriendly2[grepl("\\<climate-friendly\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateFund[grepl("\\<climate fund.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateGoals[grepl("\\<climate goal.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateIssues[grepl("\\<climate issue.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateResilient1[grepl("\\<climate resilien.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateResilient2[grepl("\\<climate-resilien.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ClimateSummit[grepl("\\<climate summit.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ConservationWork[grepl("\\<conservation work.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$COP26[grepl("\\<COP26\\>",Speeches$major_heading)] <- 1
Speeches$COP27[grepl("\\<COP27\\>",Speeches$major_heading)] <- 1
Speeches$COP28[grepl("\\<COP28\\>",Speeches$major_heading)] <- 1
Speeches$CoralReefs[grepl("\\<coral reef.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$CutEmissions[grepl("\\<cut.* emission.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Decarbon[grepl("\\<decarbon.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Deforestation[grepl("\\<deforestation\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$DEFRA1[grepl("\\<DEFRA\\>",Speeches$major_heading)] <- 1
Speeches$DEFRA2[grepl("\\<Department for Environment, food, and rural affairs\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EcolEmergency[grepl("\\<ecologial emergency\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Ecology[grepl("\\<ecolog.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ElectricCars[grepl("\\<electric car.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ElectricVehicles[grepl("\\<electric vehicl.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EmissionsTrading[grepl("\\<emissions trad.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EndangeredAnimals[grepl("\\<endangered animal.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EndangeredSpecies[grepl("\\<endangered species\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnCleanGrowth[grepl("\\<energy and clean growth\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnergyEfficiency[grepl("\\<energy efficien.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnergyPolicy[grepl("\\<energy polic.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnergyTransition[grepl("\\<energy transition\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentAgency[grepl("\\<environment.* agency\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentActivism[grepl("\\<environmental activi.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalAudit[grepl("\\<environmental audit.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalConcern[grepl("\\<environmental concern.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalDamage[grepl("\\<environmental damage.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalDestruction[grepl("\\<environmental destruction\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalImprPlan[grepl("\\<environmental improvement plan.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalIssue[grepl("\\<environmental issue.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalLeg[grepl("\\<environmental legislation\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalPlan[grepl("\\<environmental plan.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalProtection[grepl("\\<environmental protect.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalRegulation[grepl("\\<environmental regulat.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalStandards[grepl("\\<environmental standard.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$EnvironmentalSus[grepl("\\<environment.* sustaina.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ETS[grepl("\\<ETS\\>",Speeches$major_heading)] <- 1
Speeches$FeedInTariff1[grepl("\\<feed-in tariff.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$FeedInTariff2[grepl("\\<feed in tariff.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ForestPreservation[grepl("\\<forest preservation\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$FossilFuel[grepl("\\<fossil fuel.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Geothermal[grepl("\\<geothermal\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GlobalWarming[grepl("\\<global warming\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenBelt[grepl("\\<green belt.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenEconomy[grepl("\\<green econom.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenEnergy[grepl("\\<green energ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenFinance[grepl("\\<green financ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenFuture[grepl("\\<green futur.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenHomes[grepl("\\<green home.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenHousing[grepl("\\<green hous.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenIndRev[grepl("\\<green industrial revolution\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenIndustry[grepl("\\<green industr.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenInvestment[grepl("\\<green invest.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenJobs[grepl("\\<green job.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenNewDeal[grepl("\\<green new deal.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenProducts[grepl("\\<green product.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenRecovery[grepl("\\<green recovery\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenRevolution[grepl("\\<green revolution\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenTech[grepl("\\<green tech.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenTransition[grepl("\\<green transition.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenerFuture[grepl("\\<green.* future\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$GreenhouseGas[grepl("\\<greenhouse gas.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$HabitatHotsp[grepl("\\<habitat hotspot.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$HighCarbon1[grepl("\\<high carbon.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$HighCarbon2[grepl("\\<high-carbon.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$HydroPower[grepl("\\<hydro power\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$IEA[grepl("\\<IEA\\>",Speeches$major_heading)] <- 1
Speeches$InterPCC[grepl("\\<Intergovernmental Panel on Climate Change\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$InterEA[grepl("\\<International Energy Agency\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$IPCC[grepl("\\<IPCC\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$JustTransition[grepl("\\<Just Transition\\>",Speeches$major_heading)] <- 1
Speeches$LandConservation[grepl("\\<land conservation\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$LowCarbon1[grepl("\\<low carbon\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$LowCarbon2[grepl("\\<low-carbon\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$MarineCons[grepl("\\<marine conservation\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$MarineEnvironment[grepl("\\<marine environment\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Methane[grepl("\\<methane\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Microplastic[grepl("\\<microplastic.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$NativeSpecies[grepl("\\<native species\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$NaturalWorld[grepl("\\<natural world\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$NetZero[grepl("\\<net zero\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$OceanConservation[grepl("\\<ocean conservation\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$OffshoreWind1[grepl("\\<offshore wind\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$OffshoreWind2[grepl("\\<off-shore wind\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Ozone[grepl("\\<ozone\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ParisAccord[grepl("\\<Paris Accord\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ParisAgreement[grepl("\\<Paris Agreement\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ParisClimate[grepl("\\<Paris Climate\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$PlasticWaste[grepl("\\<plastic waste\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Pollution[grepl("\\<pollution\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ProtectEnv[grepl("\\<protect.* the environment\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ProtectedHabitats[grepl("\\<protected habitats\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$Recycle[grepl("\\<recylc.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$RenewableEnergy[grepl("\\<renewable energy\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$RenewablePower[grepl("\\<renewable power\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SeaLevel[grepl("\\<sea level\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SingleUse[grepl("\\<single use\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SingleUse2[grepl("\\<single-use\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SmartEnergy[grepl("\\<smart energ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SolarEnergy[grepl("\\<solar energ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SolarPanel[grepl("\\<solar panel.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SolarPV[grepl("\\<solar PV.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SolarThermal[grepl("\\<solar thermal\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SustainableEnergy[grepl("\\<sustainable energ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SustainableForestry[grepl("\\<sustainable forestry\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SustainableFuture[grepl("\\<sustainable future\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$SustainableInfra[grepl("\\<sustainable infrastructure\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$WildlifeCons[grepl("\\<wildlife conserv.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$WildlifePres[grepl("\\<wildlife preserv.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$WildlifeSanct[grepl("\\<wildlife sanctuar.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$WindEnergy[grepl("\\<wind energ.*\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$WindPower[grepl("\\<wind power\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ZeroCarbon1[grepl("\\<zero carbon\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ZeroCarbon2[grepl("\\<zero-carbon\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ZeroEmissions1[grepl("\\<zero emissions\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1
Speeches$ZeroEmissions2[grepl("\\<zero-emissions\\>",Speeches$major_heading, ignore.case = TRUE)] <- 1

## Make all NAs into 0s
Speeches <- Speeches %>% mutate(Agenda2030 = ifelse(is.na(Agenda2030), 0, Agenda2030),
                                AirQuality = ifelse(is.na(AirQuality), 0, AirQuality), 
                                AltEnergy = ifelse(is.na(AltEnergy), 0, AltEnergy),
                                AltFuel = ifelse(is.na(AltFuel), 0, AltFuel),
                                AnimalKingdom= ifelse(is.na(AnimalKingdom), 0, AnimalKingdom),
                                Biodegradable = ifelse(is.na(Biodegradable), 0, Biodegradable),
                                Biodiverse = ifelse(is.na(Biodiverse), 0, Biodiverse),
                                C02 = ifelse(is.na(C02), 0, C02),
                                CarbonBudget = ifelse(is.na(CarbonBudget), 0, CarbonBudget),
                                CarbonCapture = ifelse(is.na(CarbonCapture), 0, CarbonCapture),
                                CarbonDioxide = ifelse(is.na(CarbonDioxide), 0, CarbonDioxide),
                                CarbonEmissions = ifelse(is.na(CarbonEmissions), 0, CarbonEmissions),
                                CarbonFootprint = ifelse(is.na(CarbonFootprint), 0, CarbonFootprint),
                                CarbonNeutral = ifelse(is.na(CarbonNeutral), 0, CarbonNeutral),
                                CarbonPrice = ifelse(is.na(CarbonPrice), 0, CarbonPrice),
                                CarbonStorage = ifelse(is.na(CarbonStorage), 0, CarbonStorage),
                                CarbonTarget = ifelse(is.na(CarbonTarget), 0, CarbonTarget),
                                CarbonTax = ifelse(is.na(CarbonTax), 0, CarbonTax),
                                CircularEconomy = ifelse(is.na(CircularEconomy), 0, CircularEconomy),
                                CleanEnergy = ifelse(is.na(CleanEnergy), 0, CleanEnergy),
                                CleanGrowth = ifelse(is.na(CleanGrowth), 0, CleanGrowth),
                                ClimateAction = ifelse(is.na(ClimateAction), 0, ClimateAction),
                                ClimateActivistm = ifelse(is.na(ClimateActivistm), 0, ClimateActivistm),
                                ClimateChange = ifelse(is.na(ClimateChange), 0, ClimateChange),
                                ClimateCrisis = ifelse(is.na(ClimateCrisis), 0, ClimateCrisis),
                                ClimateDiplomacy = ifelse(is.na(ClimateDiplomacy), 0, ClimateDiplomacy),
                                ClimateEmergency = ifelse(is.na(ClimateEmergency), 0, ClimateEmergency),
                                ClimateFriendly1 = ifelse(is.na(ClimateFriendly1), 0, ClimateFriendly1),
                                ClimateFriendly2 = ifelse(is.na(ClimateFriendly2), 0, ClimateFriendly2),
                                ClimateFund = ifelse(is.na(ClimateFund), 0, ClimateFund),
                                ClimateGoals = ifelse(is.na(ClimateGoals), 0, ClimateGoals),
                                ClimateIssues = ifelse(is.na(ClimateIssues), 0, ClimateIssues),
                                ClimateResilient1 = ifelse(is.na(ClimateResilient1), 0, ClimateResilient1),
                                ClimateResilient2 = ifelse(is.na(ClimateResilient2), 0, ClimateResilient2),
                                ClimateSummit = ifelse(is.na(ClimateSummit), 0, ClimateSummit),
                                ConservationWork = ifelse(is.na(ConservationWork), 0, ConservationWork),
                                COP26 = ifelse(is.na(COP26), 0, COP26),
                                COP27= ifelse(is.na(COP27), 0, COP27),
                                COP28 = ifelse(is.na(COP28), 0, COP28),
                                CoralReefs = ifelse(is.na(CoralReefs), 0, CoralReefs),
                                CutEmissions = ifelse(is.na(CutEmissions), 0, CutEmissions),
                                Decarbon = ifelse(is.na(Decarbon), 0, Decarbon),
                                Deforestation = ifelse(is.na(Deforestation), 0, Deforestation),
                                DEFRA1 = ifelse(is.na(DEFRA1), 0, DEFRA1),
                                DEFRA2 = ifelse(is.na(DEFRA2), 0, DEFRA2),
                                EcolEmergency = ifelse(is.na(EcolEmergency), 0, EcolEmergency),
                                Ecology = ifelse(is.na(Ecology), 0, Ecology),
                                ElectricCars = ifelse(is.na(ElectricCars), 0, ElectricCars),
                                ElectricVehicles = ifelse(is.na(ElectricVehicles), 0, ElectricVehicles),
                                EmissionsTrading = ifelse(is.na(EmissionsTrading), 0, EmissionsTrading),
                                EndangeredAnimals = ifelse(is.na(EndangeredAnimals), 0, EndangeredAnimals),
                                EndangeredSpecies = ifelse(is.na(EndangeredSpecies), 0, EndangeredSpecies),
                                EnCleanGrowth = ifelse(is.na(EnCleanGrowth), 0, EnCleanGrowth),
                                EnergyEfficiency = ifelse(is.na(EnergyEfficiency), 0, EnergyEfficiency),
                                EnergyPolicy = ifelse(is.na(EnergyPolicy), 0, EnergyPolicy),
                                EnergyTransition = ifelse(is.na(EnergyTransition), 0, EnergyTransition),
                                EnvironmentAgency = ifelse(is.na(EnvironmentAgency), 0, EnvironmentAgency),
                                EnvironmentActivism= ifelse(is.na(EnvironmentActivism), 0, EnvironmentActivism),
                                EnvironmentalAudit = ifelse(is.na(EnvironmentalAudit), 0, EnvironmentalAudit),
                                EnvironmentalConcern = ifelse(is.na(EnvironmentalConcern), 0, EnvironmentalConcern),
                                EnvironmentalDamage = ifelse(is.na(EnvironmentalDamage), 0, EnvironmentalDamage),
                                EnvironmentalDestruction = ifelse(is.na(EnvironmentalDestruction), 0, EnvironmentalDestruction),
                                EnvironmentalImprPlan = ifelse(is.na(EnvironmentalImprPlan), 0, EnvironmentalImprPlan),
                                EnvironmentalIssue = ifelse(is.na(EnvironmentalIssue), 0, EnvironmentalIssue),
                                EnvironmentalLeg = ifelse(is.na(EnvironmentalLeg), 0, EnvironmentalLeg),
                                EnvironmentalPlan = ifelse(is.na(EnvironmentalPlan), 0, EnvironmentalPlan),
                                EnvironmentalProtection = ifelse(is.na(EnvironmentalProtection), 0, EnvironmentalProtection),
                                EnvironmentalRegulation = ifelse(is.na(EnvironmentalRegulation), 0, EnvironmentalRegulation),
                                EnvironmentalStandards = ifelse(is.na(EnvironmentalStandards), 0, EnvironmentalStandards),
                                EnvironmentalSus= ifelse(is.na(EnvironmentalSus), 0, EnvironmentalSus),
                                ETS = ifelse(is.na(ETS), 0, ETS),
                                FeedInTariff1 = ifelse(is.na(FeedInTariff1), 0, FeedInTariff1),
                                FeedInTariff2 = ifelse(is.na(FeedInTariff2), 0, FeedInTariff2),
                                ForestPreservation= ifelse(is.na(ForestPreservation), 0, ForestPreservation),
                                FossilFuel = ifelse(is.na(FossilFuel), 0, FossilFuel),
                                Geothermal = ifelse(is.na(Geothermal), 0, Geothermal),
                                GlobalWarming = ifelse(is.na(GlobalWarming), 0, GlobalWarming),
                                GreenBelt = ifelse(is.na(GreenBelt), 0, GreenBelt),
                                GreenEconomy= ifelse(is.na(GreenEconomy), 0, GreenEconomy),
                                GreenEnergy = ifelse(is.na(GreenEnergy), 0, GreenEnergy),
                                GreenFinance = ifelse(is.na(GreenFinance), 0, GreenFinance),
                                GreenFuture = ifelse(is.na(GreenFuture), 0, GreenFuture),
                                GreenHomes = ifelse(is.na(GreenHomes), 0, GreenHomes),
                                GreenHousing = ifelse(is.na(GreenHousing), 0, GreenHousing),
                                GreenIndRev = ifelse(is.na(GreenIndRev), 0, GreenIndRev),
                                GreenIndustry = ifelse(is.na(GreenIndustry), 0, GreenIndustry),
                                GreenInvestment = ifelse(is.na(GreenInvestment), 0, GreenInvestment),
                                GreenJobs = ifelse(is.na(GreenJobs), 0, GreenJobs),
                                GreenNewDeal = ifelse(is.na(GreenNewDeal), 0, GreenNewDeal),
                                GreenProducts = ifelse(is.na(GreenProducts), 0, GreenProducts),
                                GreenRecovery = ifelse(is.na(GreenRecovery), 0, GreenRecovery),
                                GreenRevolution = ifelse(is.na(GreenRevolution), 0, GreenRevolution),
                                GreenTech = ifelse(is.na(GreenTech), 0, GreenTech),
                                GreenTransition = ifelse(is.na(GreenTransition), 0, GreenTransition),
                                GreenerFuture = ifelse(is.na(GreenerFuture), 0, GreenerFuture),
                                GreenhouseGas= ifelse(is.na(GreenhouseGas), 0, GreenhouseGas),
                                HabitatHotsp= ifelse(is.na(HabitatHotsp), 0, HabitatHotsp),
                                HighCarbon1= ifelse(is.na(HighCarbon1), 0, HighCarbon1),
                                HighCarbon2= ifelse(is.na(HighCarbon2), 0, HighCarbon2),
                                HydroPower= ifelse(is.na(HydroPower), 0, HydroPower),
                                IEA= ifelse(is.na(IEA), 0, IEA),
                                InterPCC = ifelse(is.na(InterPCC), 0, InterPCC),
                                InterEA = ifelse(is.na(InterEA), 0, InterEA),
                                IPCC = ifelse(is.na(IPCC), 0, IPCC),
                                JustTransition = ifelse(is.na(JustTransition), 0, JustTransition),
                                LandConservation = ifelse(is.na(LandConservation), 0, LandConservation),
                                LowCarbon1 = ifelse(is.na(LowCarbon1), 0, LowCarbon1),
                                LowCarbon2 = ifelse(is.na(LowCarbon2), 0, LowCarbon2),
                                MarineCons = ifelse(is.na(MarineCons), 0, MarineCons),
                                MarineEnvironment = ifelse(is.na(MarineEnvironment), 0, MarineEnvironment),
                                Methane = ifelse(is.na(Methane), 0, Methane),
                                Microplastic = ifelse(is.na(Microplastic), 0, Microplastic),
                                NativeSpecies= ifelse(is.na(NativeSpecies), 0, NativeSpecies),
                                NaturalWorld = ifelse(is.na(NaturalWorld), 0, NaturalWorld),
                                NetZero = ifelse(is.na(NetZero), 0, NetZero),
                                OceanConservation = ifelse(is.na(OceanConservation), 0, OceanConservation),
                                OffshoreWind1= ifelse(is.na(OffshoreWind1), 0, OffshoreWind1),
                                OffshoreWind2= ifelse(is.na(OffshoreWind2), 0, OffshoreWind2),
                                Ozone = ifelse(is.na(Ozone), 0, Ozone),
                                ParisAccord = ifelse(is.na(ParisAccord), 0, ParisAccord),
                                ParisAgreement = ifelse(is.na(ParisAgreement), 0, ParisAgreement),
                                ParisClimate = ifelse(is.na(ParisClimate), 0, ParisClimate),
                                PlasticWaste = ifelse(is.na(PlasticWaste), 0, PlasticWaste),
                                Pollution = ifelse(is.na(Pollution), 0, Pollution),
                                ProtectEnv = ifelse(is.na(ProtectEnv), 0, ProtectEnv), 
                                ProtectedHabitats = ifelse(is.na(ProtectedHabitats), 0, ProtectedHabitats), 
                                Recycle = ifelse(is.na(Recycle), 0, Recycle),
                                RenewableEnergy = ifelse(is.na(RenewableEnergy), 0, RenewableEnergy),
                                RenewablePower = ifelse(is.na(RenewablePower), 0, RenewablePower),
                                SeaLevel = ifelse(is.na(SeaLevel), 0, SeaLevel),
                                SingleUse = ifelse(is.na(SingleUse), 0, SingleUse),
                                SingleUse2 = ifelse(is.na(SingleUse2), 0, SingleUse2), 
                                SmartEnergy = ifelse(is.na(SmartEnergy), 0, SmartEnergy),
                                SolarEnergy = ifelse(is.na(SolarEnergy), 0, SolarEnergy),
                                SolarPanel = ifelse(is.na(SolarPanel), 0, SolarPanel),
                                SolarPV = ifelse(is.na(SolarPV), 0, SolarPV),
                                SolarThermal = ifelse(is.na(SolarThermal), 0, SolarThermal),
                                SustainableEnergy = ifelse(is.na(SustainableEnergy), 0, SustainableEnergy),
                                SustainableForestry = ifelse(is.na(SustainableForestry), 0, SustainableForestry),
                                SustainableFuture = ifelse(is.na(SustainableFuture), 0, SustainableFuture),
                                SustainableInfra = ifelse(is.na(SustainableInfra), 0, SustainableInfra),
                                WildlifeCons = ifelse(is.na(WildlifeCons), 0, WildlifeCons),
                                WildlifePres = ifelse(is.na(WildlifePres), 0, WildlifePres),
                                WildlifeSanct = ifelse(is.na(WildlifeSanct), 0, WildlifeSanct),
                                WindEnergy = ifelse(is.na(WindEnergy), 0, WindEnergy),
                                WindPower = ifelse(is.na(WindPower), 0, WindPower),
                                ZeroCarbon1 = ifelse(is.na(ZeroCarbon1), 0, ZeroCarbon1),
                                ZeroCarbon2 = ifelse(is.na(ZeroCarbon2), 0, ZeroCarbon2),
                                ZeroEmissions1 = ifelse(is.na(ZeroEmissions1), 0, ZeroEmissions1),
                                ZeroEmissions2 = ifelse(is.na(ZeroEmissions2), 0, ZeroEmissions2))


## add all variables to make the dummy

Speeches$DebateTopic<-rowSums(cbind(Speeches$Agenda2030, Speeches$AirQuality ,Speeches$AltEnergy, Speeches$AltFuel, Speeches$AnimalKingdom, Speeches$Biodegradable, 
                                    Speeches$Biodiverse, Speeches$C02, Speeches$CarbonBudget , Speeches$CarbonCapture, Speeches$CarbonDioxide, Speeches$CarbonEmissions, 
                                    Speeches$CarbonFootprint,Speeches$CarbonNeutral, Speeches$CarbonPrice , Speeches$CarbonStorage , Speeches$CarbonTarget , 
                                    Speeches$CarbonTax ,Speeches$CircularEconomy ,Speeches$CleanEnergy , Speeches$CleanGrowth , Speeches$ClimateAction, 
                                    Speeches$ClimateActivistm , Speeches$ClimateChange ,Speeches$ClimateCrisis , Speeches$ClimateDiplomacy , Speeches$ClimateEmergency,
                                    Speeches$ClimateFriendly1,Speeches$ClimateFriendly2, Speeches$ClimateFund , Speeches$ClimateGoals , Speeches$ClimateIssues ,
                                    Speeches$ClimateResilient1, Speeches$ClimateResilient2 , Speeches$ClimateSummit ,  Speeches$ConservationWork ,  Speeches$COP26 ,
                                    Speeches$COP27, Speeches$COP28 , Speeches$CoralReefs, Speeches$CutEmissions ,Speeches$Decarbon , Speeches$Deforestation, Speeches$DEFRA1,
                                    Speeches$DEFRA2, Speeches$EcolEmergency , Speeches$Ecology ,Speeches$ElectricCars ,Speeches$ElectricVehicles , Speeches$EmissionsTrading ,
                                    Speeches$EndangeredAnimals , Speeches$EndangeredSpecies ,  Speeches$EnCleanGrowth , Speeches$EnergyEfficiency , Speeches$EnergyPolicy, 
                                    Speeches$EnergyTransition ,Speeches$EnvironmentAgency , Speeches$EnvironmentActivism,  Speeches$EnvironmentalAudit ,  
                                    Speeches$EnvironmentalConcern, Speeches$EnvironmentalDamage ,  Speeches$EnvironmentalDestruction, 
                                    Speeches$EnvironmentalImprPlan,Speeches$EnvironmentalIssue, Speeches$EnvironmentalLeg , Speeches$EnvironmentalPlan ,  
                                    Speeches$EnvironmentalProtection , Speeches$EnvironmentalRegulation ,Speeches$EnvironmentalStandards ,Speeches$EnvironmentalSus, Speeches$ETS ,
                                    Speeches$FeedInTariff1 , Speeches$FeedInTariff2 ,Speeches$ForestPreservation, Speeches$FossilFuel , Speeches$Geothermal ,Speeches$GlobalWarming ,
                                    Speeches$GreenBelt , Speeches$GreenEconomy, Speeches$GreenEnergy , Speeches$GreenFinance, Speeches$GreenFuture , Speeches$GreenHomes ,Speeches$GreenHousing , 
                                    Speeches$GreenIndRev , Speeches$GreenIndustry, Speeches$GreenInvestment ,  Speeches$GreenJobs , Speeches$GreenNewDeal , Speeches$GreenProducts ,
                                    Speeches$GreenRecovery, Speeches$GreenRevolution, Speeches$GreenTech , Speeches$GreenTransition , Speeches$GreenerFuture , 
                                    Speeches$GreenhouseGas, Speeches$HabitatHotsp, Speeches$HighCarbon1,  Speeches$HighCarbon2, Speeches$HydroPower, Speeches$IEA, Speeches$InterPCC , 
                                    Speeches$InterEA , Speeches$IPCC,  Speeches$JustTransition , Speeches$LandConservation , Speeches$LowCarbon1, Speeches$LowCarbon2 , Speeches$MarineCons ,
                                    Speeches$MarineEnvironment , Speeches$Methane ,  Speeches$Microplastic, Speeches$NativeSpecies, Speeches$NaturalWorld ,  Speeches$NetZero , 
                                    Speeches$OceanConservation,Speeches$OffshoreWind1,  Speeches$OffshoreWind2, Speeches$Ozone , Speeches$ParisAccord,  Speeches$ParisAgreement , 
                                    Speeches$ParisClimate , Speeches$PlasticWaste, Speeches$Pollution , Speeches$ProtectEnv , Speeches$ProtectedHabitats, Speeches$Recycle , 
                                    Speeches$RenewableEnergy , Speeches$RenewablePower, Speeches$SeaLevel , Speeches$SingleUse , Speeches$SingleUse2, Speeches$SmartEnergy , Speeches$SolarEnergy , 
                                    Speeches$SolarPanel ,Speeches$SolarPV ,Speeches$SolarThermal ,   Speeches$SustainableEnergy , Speeches$SustainableForestry , 
                                    Speeches$SustainableFuture , Speeches$SustainableInfra , Speeches$WildlifeCons , Speeches$WildlifePres,  Speeches$WildlifeSanct , 
                                    Speeches$WindEnergy, Speeches$WindPower ,Speeches$ZeroCarbon1 , Speeches$ZeroCarbon2, Speeches$ZeroEmissions1, Speeches$ZeroEmissions2 ))

nrow(Speeches) ## 687,699 observations
View(Speeches)

Speeches <- Speeches[, c("mnis_id", "speakername", "date", "year", "party", "constituency", "major_heading", "minor_heading", "gender", "start_date", "gvt_role", "opp_role", "parly_role", "EnvWords", "EnvDummy", "DebateTopic", "EnvCommittee", "YearsExp", "RulingParty")]
Speeches$DebateTopic <- ifelse(Speeches$DebateTopic >= 1, 1, 0)
nrow(Speeches) ## 687,669 observations


## EXPORT FINAL DATA
write.csv(Speeches, "2010FinalData.csv", row.names = FALSE, quote = TRUE)

## Resume analysis in New Doc